{include file='public/head' /}
<style type="text/css">
  .tablelist tr {
    border:1px solid #CFCFCF;
  }
  .tablelist tr td,.tablelist tr th{
    border:1px solid #CFCFCF;
  }
</style>
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main" style="padding:10px">
        <h1 class="page-header" style="color: #3399CC">管理员列表
          <button type="button" class="btn btn-info"  title="添加用户" onclick="javascript:window.location.href='{:url('admin/admin/add')}'"><span class="glyphicon glyphicon glyphicon-plus"></span> 添加管理员</button>
          <button type="button" class="btn btn-danger"  title="删除全部选中" id="deleteSelect"><span class="glyphicon glyphicon-trash"></span> 批量删除</button>
        </h1>
        <div class="table-responsive" style="margin-top: -30px;border:none;">
          <form action="{:url('admin/admin/index')}" method="get" class="navbar-form navbar-right" role="search" style="margin-top: 20px;">
           <div class="input-group">
              <input type="text" class="form-control" autocomplete="off" placeholder="键入关键字搜索" value='{$Think.get.key}' name="key" style="width:190px">
            <span class="input-group">
             <input class="btn btn-primary" type="submit" value="搜索" style="border-radius: 0 3px 3px 0">&nbsp;
             <button class="btn btn-primary" name="all" value="1">显示全部</button>
              </span> </div>
           </form>
          <table class="table table-striped table-hover tablelist">
            <thead>
              <tr style="background-color: #3399CC;color: white">
                <th><input type="checkbox" id="all" style="position: relative;top:2px"/><span class="glyphicon glyphicon-th-large"></span> <span>选择</span></th>
                <th><span class="glyphicon glyphicon-user"></span> <span>用户名</span></th>
                <th><span class="glyphicon glyphicon-map-marker"></span> <span>IP</span></th>
                <th><span class="glyphicon glyphicon-map-marker"></span> <span>IP地址</span></th>
                <th><span class="glyphicon glyphicon-tags"></span> <span>登录次数</span></th>
                <th><span class="glyphicon glyphicon-users"></span> <span>用户组</span></th>
                <th><span class="glyphicon glyphicon-pencil"></span> <span>操作</span></th>
              </tr>
            </thead>
            <tbody>
              {volist name="data" id="vo"}
              <tr>
                <td>
                  {if condition="$vo.admin_id eq 1"}
                  <input type="checkbox" class="input-control disabled" onclick="return false;"/>
                  {else/}
                  <input type="checkbox" class="input-control" value="{$vo.admin_id}"/>
                  {/if}
                  {$vo.admin_id}
                </td>
                <td>{$vo.user_name}</td>
                <td>{$vo.loginip}</td>
                <td>{$vo.ipadress}</td>
                <td>{$vo.loginnum}</td>
                <td>
                  {if condition="$vo.group_id eq 1"}
                  超级管理员
                  {elseif condition="$vo.group_id eq 2"}
                  管理员
                  {elseif condition="$vo.group_id eq 3"}
                  游客
                  {else /}
                  其他
                  {/if}
                </td>
                <td>
                  <a href="{:url('seelist',['admin_id'=>$vo.admin_id])}" title="查看" rel="1" class="btn btn-success btn-xs" name="see" style="font-size: 10px;"><span class="glyphicon glyphicon-zoom-in"></span> 查看</a>
                  <a href="{:url('edit',['admin_id'=>$vo.admin_id])}" title="编辑" rel="1" class="btn btn-primary btn-xs" name="see" style="font-size: 10px;"><span class="glyphicon glyphicon-pencil"></span> 编辑</a>
                  {if condition="$vo.admin_id eq 1"}
                   <a title="删除" rel="1" class="btn btn-danger btn-xs disabled" name="see" style="font-size: 10px;"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                  {else/}
                  <a href="{:url('del',['admin_id'=>$vo.admin_id])}" title="删除" rel="1" class="btn btn-danger btn-xs del" name="see" style="font-size: 10px;"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                  {/if}
              </tr>  
              {/volist}
            </tbody>
          </table>
        </div>
        <footer class="message_footer" style="margin-top: -10px;">
        {if condition="$all eq 1"}
        {else/}
        <span style="float: left;margin-top: 15px;">第{$data->currentPage()} 页 / 共 {$data->lastPage()} 页 ( 总 共 {$data->total()} 条 记 录 )</span> 
        <div style="float: right;margin-top: -10px;">  
        <div class="page" style="margin-top: 5px;">
        {$data->render()}
        </div>
        </div>
        {/if}
        </footer>
    </div>
  </div>
</section>
<script>
  //单条记录删除
  $('.del').click(function(){
      var del = confirm("你确定要删除吗？");
       if(del == false){
        return false;
      }  
  });
  //多选删除
  $('#deleteSelect').click(function(){
    //获取【被选择】的行的id
      var trObj = $(".tablelist tbody tr");
      var ids = new Array();
      var mainObjs = new Array();
      //遍历每一行
      for($i=0;$i<trObj.length;$i++){
         if(trObj.eq($i).find("input").attr('checked')){
            //组装ids数组
            ids[ids.length]=trObj.eq($i).find("input").val();
            //组装mainObj数组
            mainObjs[mainObjs.length]=trObj.eq($i);
         }
      }   
    if(ids.length>0){
        //启动ajax
        $.ajax({
            url:"{:url('deleteall')}",
            type:'post',
            data:{'admin_id':ids},
            async:false, 
            dataType:'json',
            success:function (d) {
                console.log(d);
            if(d==1) {
                var a = confirm("你确定要删除吗？");
                if(a == true){
                   //将前端被选择的多选框所在的行移除DOM
                    for($i=0;$i<mainObjs.length;$i++){
                        mainObjs[$i].fadeOut(500,function(){
                            $(this).remove();
                            history.go(0);
                        });
                    }
                }else{
                   history.go(0);
                }
              } else if (d == 2) {
                     //删除失败
                   alert('删除失败');
               }

            }

        });
    }else{
       alert("你没有选择要删除的内容，请选择后再【批量删除】");
    }  
 
  });
  //全选或全不选
  $("#all").click(function(){ 
      if(this.checked){
         $(".tablelist tbody tr :checkbox").attr("checked", true);
        
      }else{
         $(".tablelist tbody tr :checkbox").removeAttr("checked", false);
      }
  });
</script>
</body>
</html>
